//
//  XDSingleBtnCell.m
//  XDEducation
//
//  Created by apple on 2017/4/14.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDSingleBtnCell.h"

@interface XDSingleBtnCell ()

/** button */
@property(nonatomic,strong) UIButton *button;
@end

static NSString *const cellId = @"XDSingleBtnCell";

@implementation XDSingleBtnCell

+(instancetype)cellWithTableView:(UITableView *)tableView{

    XDSingleBtnCell *cell = [[XDSingleBtnCell alloc]init];
    
    if (!cell) {
        cell = [[XDSingleBtnCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _button = [[UIButton alloc]init];
        [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_button setTitle:@"下一步" forState:UIControlStateNormal];
        [_button setBackgroundImage:[UIImage imageNamed:@"list_btn_unit_selected"] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_button];
        
        [_button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
    
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    [_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_offset(48*ScaleHeight);
    }];
}

-(void)setTitle:(NSString *)title{
    
    _title = title;
     [_button setTitle:_title forState:UIControlStateNormal];
}

-(void)buttonClicked{
    if (self.buttonClickedBlock) {
        self.buttonClickedBlock();
    }
}

@end
